package com.bjtech.dao.ibatis;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;
import org.ssi.dao.impl.BaseDaoSqlMapImpl;

import com.bjtech.dao.BaseBuildingInfoDao;
import com.bjtech.domain.BaseBuildingInfo;
import com.bjtech.domain.BaseShareAreaInfo;

/**
 * @author wf
 *
 */
@Repository(value="baseBuildingInfoDao")
public class SqlMapBaseBuildingInfoDao extends BaseDaoSqlMapImpl<BaseBuildingInfo> implements
		BaseBuildingInfoDao {

	public List selectBudilingListByAreaId(Long areaId) {
		return super.getSqlMapClientTemplate().queryForList("selectBudilingListByAreaId",areaId);
	}

	public void deleteBuildingInfoLinkedObj(Long id) {
		super.getSqlMapClientTemplate().delete("deleteAssignMeterInfoByBuildId",id);
		super.getSqlMapClientTemplate().delete("deleteSinkInfoByBuildId",id);
		super.getSqlMapClientTemplate().delete("deleteRoomInfoByBuildId",id);		
	}

	public Map selectTjParam(Long buildId) {
		Map tjParam = new HashMap();
		//参与计量户数量
		Long joinFtNum = (Long) super.getSqlMapClientTemplate().queryForObject("selectBuidlingJoinNumTjInfo",buildId);
		tjParam.put("joinFtNum",joinFtNum);
		
		//不参与计量户数量
		Long notJoinFtNum = (Long) super.getSqlMapClientTemplate().queryForObject("selectBuidlingNotJoinNumTjInfo",buildId);
		tjParam.put("notJoinFtNum",notJoinFtNum);
		
		//户参与率
		if(joinFtNum+notJoinFtNum>0){
			tjParam.put("joinPercent",new Float(joinFtNum*1000/(joinFtNum+notJoinFtNum))/10);
		}else{
			tjParam.put("joinPercent",0);
		}
		
		//楼栋建筑总面积
		BigDecimal build_struct_area = (BigDecimal)super.getSqlMapClientTemplate().queryForObject("selectBuidlingStructAreaInfo",buildId);
		tjParam.put("build_struct_area",build_struct_area);
		
		//楼栋状态
//		String build_state  = (BaseShareAreaInfo)super.getSqlMapClientTemplate().queryForObject("selectBaseShareAreaInfo", parameterObject)
//		= (String)
		
		//楼栋单元数量
		Long unit_no = (Long) super.getSqlMapClientTemplate().queryForObject("selectBuidlingUnitTjInfo",buildId);
		tjParam.put("unit_no",unit_no);
		
		//换热站名
//		stationName
		
		//楼栋总户数
		Long build_user_num= (Long) super.getSqlMapClientTemplate().queryForObject("selectBuidlingUserNumTjInfo",buildId);
		tjParam.put("build_user_num",build_user_num);
		
		//楼洞供热面积
		BigDecimal build_heat_area = (BigDecimal)super.getSqlMapClientTemplate().queryForObject("selectBuidlingHeatAreaInfo",buildId);
		tjParam.put("build_heat_area",build_heat_area);

		//楼栋散热器数量
		Long build_sink_num= (Long) super.getSqlMapClientTemplate().queryForObject("selectBuidlingSinkNumTjInfo",buildId);
		tjParam.put("build_sink_num",build_sink_num);
		
		//楼栋分配表总数量
		Long build_assign_num= (Long) super.getSqlMapClientTemplate().queryForObject("selectBuidlingAssignNumTjInfo",buildId);
		tjParam.put("build_assign_num",build_assign_num);
		return tjParam;
	}

	public List selectBulidingListByPIndexForReport(Long projId) {
		List list = super.getSqlMapClientTemplate().queryForList("selectBulidingListByPIndexForReport",projId);
		return list;
	}

	public static void main(String[] args){
		System.out.println(new Float(46*1000/47)/10);
	}
}
